{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Polygon():\n",
    "    \"\"\"A class to capture common utilities for dealing with shapes\"\"\"\n",
    "    def __init__(self, side_lengths):\n",
    "        self.side_lengths = side_lengths\n",
    "        \n",
    "    def __str__(self):\n",
    "        return 'Polygon with %s sides' % self.num_sides \n",
    "        \n",
    "    @property\n",
    "    def num_sides(self):\n",
    "        return len(self.side_lengths)\n",
    "        \n",
    "    @property\n",
    "    def perimeter(self):\n",
    "        return sum(self.side_lengths)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Rectangle(Polygon):\n",
    "    def __init__(self, height, width):\n",
    "        super().__init__([height, width, height, width])\n",
    "        \n",
    "    @property\n",
    "    def area(self):\n",
    "        return self.side_lengths[0] * self.side_lengths[1]       "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5, 12)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r = Rectangle(1, 5)\n",
    "r.area, r.perimeter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Square(Rectangle):\n",
    "    def __init__(self, height):\n",
    "        super().__init__(height, height)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(25, 20)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = Square(5)\n",
    "s.area, s.perimeter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
